/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package battleship.game;

import java.util.Random;
import util.MsgPrinter;

/**
 *
 * @author ali
 */
public class StatePlayer2Turn extends AbstractState {

    private static AbstractState instance;

    public static AbstractState getInstance() {
        if (instance == null) {
            instance = new StatePlayer2Turn();
        }
        return instance;
    }

    /**
     * If we want to introduce a Hard Level, we need to add an artificial intelligence
     * through which the computer will select the x,y location to hit in much more
     * intelligent way.
     *
     * Currently, it is doing in a random manner.
     */
    @Override
    public void execute() {
        MsgPrinter.print("\nComputer's turn");
        Random random = new Random();
        int x = random.nextInt(11);
        int y = random.nextInt(11);
        try {
            boolean wasHitPossible = Game.getHumanPlayer().getBoard().hit(x, y);

        } catch (IllegalArgumentException e) {
            String playerName = Game.getCompPlayer().getName();
            String hint = "Incorrect values entered. " + playerName + " wasted turn";
            MsgPrinter.print(hint);
        }
    }

    @Override
    public StateType getNextState() {
        AbstractState statePlayer1Turn = StatePlayer1Turn.getInstance();
        AbstractState stateCheckWinner = StateCheckWinner.getInstance(statePlayer1Turn);
        return stateCheckWinner;
    }
}
